<template>
  <div class="liumian">
    <div class="content_title" v-if="!inline">
      <span @click="showDialogTech" style="cursor:pointer">
        <span class="content_text">梳棉</span>
        <img class="content_img" src="../assets/img/resource/icon/liumian.png" alt="" srcset="" />
      </span>
    </div>
    <div class="liumian_body">
      <div class="liumianRol">
        <div v-for="(item, index) in liumianData.liumianRow1Data" :key="index + 'g'" class="liumian_item">
          <div v-if="index == 7">
            <div class="dongli" @click="clickHandleDl('shumian1_' + index)">
              <img src="../assets/img/donglis.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('liumian', item)">
            <liumian :data="item" :inline="inline"></liumian>
          </div>
        </div>
      </div>
      <div class="liumianRol">
        <div v-for="(item, index) in liumianData.liumianRow2Data" :key="index + 'h'" class="liumian_item">
          <div v-if="index == 7">
            <div class="dongli" @click="clickHandleDl('shumian2_' + index)">
              <img src="../assets/img/donglis.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('liumian', item)">
            <liumian :data="item" :inline="inline"></liumian>
          </div>
        </div>
      </div>
      <div class="liumianRol">
        <div v-for="(item, index) in liumianData.liumianRow3Data" :key="index + 'j'" class="liumian_item">
          <div v-if="index == 7">
            <div class="dongli" @click="clickHandleDl('shumian3_' + index)">
              <img src="../assets/img/donglis.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('liumian', item)">
            <liumian :data="item" :inline="inline"></liumian>
          </div>
        </div>
      </div>
      <div class="liumianRol">
        <div v-for="(item, index) in liumianData.liumianRow4Data" :key="index + 'k'" class="liumian_item">
          <div v-if="index == 7">
            <div class="dongli" @click="clickHandleDl('shumian4_' + index)">
              <img src="../assets/img/donglis.svg" alt="" srcset="" />
            </div>
          </div>
          <div @click="clickHandle('liumian', item)">
            <liumian :data="item" :inline="inline"></liumian>
          </div>
        </div>
      </div>
    </div>
    <!-- 梳棉弹窗控件 -->
    <liumianDialog ref="liumianDialog"></liumianDialog>
    <!-- 动力柜弹窗控件 -->
    <dongliDialog ref="dongliDialog"></dongliDialog>
    <!-- 梳棉工艺详情 -->
    <shumian-dialog-tech v-if="techShow" ref="shumianDialogTech"></shumian-dialog-tech>
  </div>
</template>

<script>
import dongliDialog from "../views/qcs/components/dialog/dialog_dongli/index";
import liumianDialog from "../views/qcs/components/dialog/dialog_liumian/index";
import liumian from "../views/qcs/components/liumian";
import COMMON from "../utils/common";
import dongLiMenu from "@/assets/data/dongli.json";
import dongliItem from "@/assets/data/dongliItem.json";
export default {
  name: "ShuMian",
  props: {
    msg: String,
    // 是否嵌套在弹窗内
    inline: {
      type: Boolean,
      default: false
    }
  },
  components: {
    dongliDialog,
    liumian,
    liumianDialog
  },
  data() {
    return {
      liumianData: {
        // 1-8
        liumianRow1Data: [],
        // 9-16
        liumianRow2Data: [],
        // 17-24
        liumianRow3Data: [],
        // 25-32
        liumianRow4Data: [],
        dongLiMenu: {},
        dongLiItem: {}
      },
      techShow: false
    };
  },
  // 组件相互调用 需在beforeCreate注册
  beforeCreate: function() {
    this.$options.components.shumianDialogTech = require("../views/qcs/components/dialogBig/dialog_shumian_tech/index").default;
  },
  created() {
    this.dongLiMenu = dongLiMenu;
    this.dongLiItem = dongliItem;
  },
  methods: {
    closeHandle(type) {
      // 若梳棉组件在1.5级弹窗内，当关闭二级弹窗时，需要打开1.5级的轮询
      if (this.inline) {
        if (type == "secShuMianJi") {
          this.$EventBus.$emit("clearTypeInterval", "secShuMianJiATimer");
          this.$EventBus.$emit("clearTypeInterval", "secShuMianJiTimer");
        } else {
          // 关闭二级轮询
          this.$EventBus.$emit("clearTypeInterval", type);
        }
        this.$parent.$parent.getTableData();
      } else {
        this.$parent.closeParentHandle();
      }
    },
    clickHandle(flag, item) {
      // 若并条组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "SHUMIANJI", item.devSn);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("SHUMIANJI", item.devSn);
      }
      this.$refs.liumianDialog.showDialog(item);
    },
    clickHandleDl(item) {
      var getInfoQuary = this.dongLiMenu[item];
      var dialogData = this.dongLiItem[item];
      // 若并条组件在1.5级弹窗内，当打开二级弹窗时，需要关闭1.5级的轮询
      if (this.inline) {
        this.$EventBus.$emit("getInfoByDevSn", "DONGLI", getInfoQuary);
        this.$EventBus.$emit("inlineDialog", "close");
      } else {
        this.$parent.getInfoByDevSn("DONGLI", getInfoQuary);
      }
      this.$refs.dongliDialog.showDialog(dialogData);
    },
    showDialogTech() {
      this.techShow = true;
      this.$nextTick(() => {
        setTimeout(() => {
          // 初始化请求
          // 1.5级轮询
          this.$parent.openInlineDialog("SHUMIAN", { start: 1, end: 32 });
          this.$refs.shumianDialogTech.showDialog();
        });
      });
    },
    closeDialogTech() {
      this.techShow = false;
      this.$parent.closeParentHandle();
    }
  },
  computed: {
    shuMianJiGroupState() {
      return this.$store.state.shuMianJiGroupState;
    }
  },
  watch: {
    shuMianJiGroupState: {
      immediate: true,
      handler(val) {
        this.liumianData.liumianRow1Data = COMMON.devSnFilter(val.data1, 1, 8);
        this.liumianData.liumianRow2Data = COMMON.devSnFilter(val.data1, 9, 16);
        this.liumianData.liumianRow3Data = COMMON.devSnFilter(val.data2, 17, 24);
        this.liumianData.liumianRow4Data = COMMON.devSnFilter(val.data2, 25, 32);
      }
    }
  }
};
</script>

<style scoped></style>
